package com.miyake.dsp.osa.lab.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import com.miyake.dsp.osa.lab.SettingPanelListener;
import com.miyake.dsp.otdr.OtdrRxSetting;

public class SequencerSettingPanelUI extends SettingPanelUI {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3736792212172219215L;

	class SequencerThread extends Thread {
		@Override
		public void run() {
			while(!stop) {
				fireOnSet();
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		
	}

	protected boolean stop;;
	
	@Override
	protected void createCustomComponent(Object o) {
		/*
		final OtdrRxSetting setting = (OtdrRxSetting)o;
		setting.setSamplingFrequency(1e8);
		setting.setBandwidth(1e7);
		setting.setCeiling(1e-4);
		setting.setMovingAverage(1);
		setting.setNoise(1e-5);
		*/
		final JButton runButton = new JButton("Run");
		add(runButton);
		runButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				stop = false;
				runButton.setEnabled(false);
				new SequencerThread().start();
			}
		});
		JButton stopButton = new JButton("Stop");
		add(stopButton);
		stopButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				stop = true;
				runButton.setEnabled(true);
			}
		});
	}

	public SequencerSettingPanelUI(Object o, SettingPanelListener listener) {
		super(o, listener);
		// TODO Auto-generated constructor stub
	}

}
